package edu.cs3240.main;

import java.util.Stack;

import javax.swing.JFrame;

import edu.cs3240.nfa.Part;
import edu.cs3240.nfa.State;
import edu.cs3240.nfa.Transition;
import edu.cs3240.visual.GraphVisualization;
public class Driver {
	
	public static void main(String[] args)
	{

		Part part = Parse("((a|b)|(b|c))");
		
		GraphVisualization frame = new GraphVisualization(part);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(800, 600);
		frame.setVisible(true);
		
		
	}	
	
	public static Part Parse(String regex)
	{
		int charIndex = 0;
		
		Stack<Part> parts = new Stack<Part>();
		parts.push(new Part());
		
		while(charIndex < regex.length())
		{
			char letter = regex.charAt(charIndex);
			charIndex++;
			
			if(letter == '(')
			{
				parts.push(new Part());
			}
			else if(letter == ')')
			{
				Part temp = parts.pop();
				parts.peek().union(temp);
			}
			else if(letter == '|')
			{
				Part temp = parts.pop();
				parts.peek().union(temp);
				parts.push(new Part());
			}
			else
			{			
				State state = new State();
				state.addTransition(new Transition(state, null, letter));
				parts.peek().concat(state);
			}
		}
		
		return parts.peek();
	}
}
